<template>
    <view>
        <!-- pages/gerenzhongxin/tixian.wxml -->
        <!-- <header name="提现" type="1"></header> -->
        <view class="slist" v-if="!isshiming">
            <text>真实姓名</text>
            <input type="text" placeholder="输入真实姓名" :value="name" @input="onInput1" data-name="name" placeholder-style="color: #D7DAE0;" />
        </view>
        <view class="czje">
            <view class="czje1">提现金额</view>
            <view class="qianshu">
                <text>￥</text>
                <input type="number" :value="money" @input="onInput" />
            </view>
            <view class="wdye">
                我的余额：{{ yue || 0.0 }}元
                <text @tap="alltixian">全部提现</text>
            </view>
            <text class="tips">服务费为{{ lv }}%（最低提现{{ min }}）</text>
            <view class="btn" @tap="submit">提现</view>
        </view>
    </view>
</template>

<script>
import header from '../../components/header/headerBar.vue';
// pages/ucenter/tixian.js
var app = getApp();
export default {
    components: {
        header
    },
    data() {
        return {
            flag: true,
            isshiming: false,
            yue: '',
            lv: '',
            min: '',
            name: '',
            money: '',
            sfz_a: '',
            sfz_b: '',
            fdata: ''
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        app.globalData.http('app/center/inittixian', {}, function (res) {
            if (res.code == 0) {
                that.setData({
                    yue: res.data.yue,
                    lv: Number(res.data.lv) * 100,
                    min: res.data.min,
                    name: res.data.name
                });
            }
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    // onShareAppMessage: function () {
    // }
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */ methods: {
        onInput1(e) {
            var _this = this;

            this.setData({
                name: e.detail.value
            });
        },

        alltixian() {
            if (this.yue > 0) {
                this.setData({
                    money: this.yue
                });
            }
        },

        onInput(e) {
            this.setData({
                money: e.detail.value
            });
        },

        upimg(e) {
            var _this = this;

            var name = e.currentTarget.dataset.name;
            uni.chooseImage({
                count: 1,
                // 默认9
                sizeType: ['compressed'],
                // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'],
                // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    uni.showLoading({
                        title: '加载中'
                    });
                    var tempPath = res.tempFilePaths;

                    for (var i = 0; i < tempPath.length; i++) {
                        uni.uploadFile({
                            url: app.globalData.http('upfiles'),
                            filePath: tempPath[i],
                            name: 'file',

                            success(res2) {
                                var data = JSON.parse(res2.data);
                                uni.hideLoading();

                                switch (name) {
                                    case 'sfz_a':
                                        if (data.data.indexOf('http') != -1) {
                                            _this.sfz_a = data.data;
                                        } else {
                                            _this.sfz_a = 'https://xiao.qilurenzuntang.com' + data.data;
                                        }

                                        _this.setData({
                                            sfz_a: _this.sfz_a
                                        });

                                        break;

                                    case 'sfz_b':
                                        if (data.data.indexOf('http') != -1) {
                                            _this.sfz_b = data.data;
                                        } else {
                                            _this.sfz_b = 'https://xiao.qilurenzuntang.com' + data.data;
                                        }

                                        _this.setData({
                                            sfz_b: _this.sfz_b
                                        });

                                        break;

                                    case 'compic':
                                        if (data.data.indexOf('http') != -1) {
                                            _this.fdata.compic = data.data;
                                        } else {
                                            _this.fdata.compic = 'https://xiao.qilurenzuntang.com' + data.data;
                                        }

                                        _this.setData({
                                            fdata: _this.fdata
                                        });

                                        break;
                                }
                            }
                        });
                    }
                }
            });
        },

        submit() {
            var _this = this;

            if (!this.money) {
                uni.showToast({
                    title: '请输入提现金额',
                    icon: 'none'
                });
                return false;
            }

            if (_this.isshiming) {
                if (!this.name) {
                    uni.showToast({
                        title: '请输入真实姓名',
                        icon: 'none'
                    });
                    return false;
                }
            }

            app.globalData.http(
                'app/center/uptixian',
                {
                    name: this.name,
                    money: this.money
                },
                function (res) {
                    if (res.code == 0) {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none'
                        });
                        setTimeout(() => {
                            uni.navigateBack({
                                delta: 1
                            });
                        }, 1200);
                    } else {
                    }
                }
            );
        }
    }
};
</script>
<style lang="scss"> @import 'main.scss';
@import './tixian.scss';
</style>
